<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>编辑出院长者准备表</title>
	<#include "/common/resource.ftl">
    <link rel="stylesheet" href="${params.contextPath}/static/plug/layui/css/layui.css">
    <link rel="stylesheet" href="${params.contextPath}/static/css/jquery-ui.min.css">
    <script src="${params.contextPath}/static/js/jquery-ui.min.js"></script>
    <style>
        .layui-form select {display:none !important;}
    </style>
	<script type="text/javascript">
		$(function () {
            LocalStorage.registHandler("elder_handler_select", function (data) {
                $('input[name="elderId"]').val(data.id);
                $('input[name="elderName"]').val(data.name);
            });
            <#if (params.tag)??>
            $( "#elderName").autocomplete({
                source: function(request, response) {
                    $.ajax({
                        url: "${params.contextPath}/web/elder/listAll.json",
                        dataType: "json",
                        data: {
                            name: $("#elderName").val().trim()
                        },
                        success: function(data) {
                            response($.map(data.data, function(item) {
                                return {
                                    value: item.name,
                                    id: item.id
                                }
                            }));
                        }
                    });

                },
                select: function(e, ui) {
                    $("[name='elderId']").val(ui.item.id);
                },
                maxLength: 2
            });
            </#if>
			<#if (params.id)??>
				$.ajaxRequest({
					url: '${params.contextPath}/web/dischargeElderPreparation/query.json',
					data: {id: "${params.id}"},
					success: function (data) {
						if (!data.success) {
							$.message(data.message);
							return;
						}
						var record = data.data;
						for (var key in record) {
                            if (key == 'fillForm') {
                                var fillForm = record.fillForm;
                                var fillFormArray = fillForm.split(",");
                                var fillFormAll = $("input[name='fillForm']");
                                for(var i=0; i<fillFormArray.length; i++){
                                    //获取所有复选框对象的value属性，然后，symptomArray[i]和他们匹配，如果有，则说明他应被选中
                                    $.each(fillFormAll,function(j,checkbox){
                                        //获取复选框的value属性
                                        var checkValue = $(checkbox).val();
                                        if(fillFormArray[i] == checkValue){
                                            $(checkbox).attr("checked",true);
                                            // $(checkbox).next().addClass('layui-form-checked');
                                        }
                                    });
                                }
                            } else if (key == 'notebook') {
                                var notebook = record.notebook;
                                var notebookArray = notebook.split(",");
                                var notebookAll = $("input[name='notebook']");
                                for(var i=0; i<notebookArray.length; i++){
                                    //获取所有复选框对象的value属性，然后，symptomArray[i]和他们匹配，如果有，则说明他应被选中
                                    $.each(notebookAll,function(j,checkbox){
                                        //获取复选框的value属性
                                        var checkValue = $(checkbox).val();
                                        if(notebookArray[i] == checkValue){
                                            $(checkbox).attr("checked",true);
                                            // $(checkbox).next().addClass('layui-form-checked');
                                        }
                                    });
                                }
                            } else if (key == 'itemRecycle') {
                                var itemRecycle = record.itemRecycle;
                                var itemRecycleArray = itemRecycle.split(",");
                                var itemRecycleAll = $("input[name='itemRecycle']");
                                for(var i=0; i<itemRecycleArray.length; i++){
                                    //获取所有复选框对象的value属性，然后，symptomArray[i]和他们匹配，如果有，则说明他应被选中
                                    $.each(itemRecycleAll,function(j,checkbox){
                                        //获取复选框的value属性
                                        var checkValue = $(checkbox).val();
                                        if(itemRecycleArray[i] == checkValue){
                                            $(checkbox).attr("checked",true);
                                            // $(checkbox).next().addClass('layui-form-checked');
                                        }
                                    });
                                }
                            } else if (key == 'returnElder') {
                                var returnElder = record.returnElder;
                                var returnElderArray = returnElder.split(",");
                                var returnElderAll = $("input[name='returnElder']");
                                for(var i=0; i<returnElderArray.length; i++){
                                    //获取所有复选框对象的value属性，然后，symptomArray[i]和他们匹配，如果有，则说明他应被选中
                                    $.each(returnElderAll,function(j,checkbox){
                                        //获取复选框的value属性
                                        var checkValue = $(checkbox).val();
                                        if(returnElderArray[i] == checkValue){
                                            $(checkbox).attr("checked",true);
                                            // $(checkbox).next().addClass('layui-form-checked');
                                        }
                                    });
                                }
                            } else if (key == 'roomHygiene') {
                                var roomHygiene = record.roomHygiene;
                                var roomHygieneArray = roomHygiene.split(",");
                                var roomHygieneAll = $("input[name='roomHygiene']");
                                for(var i=0; i<roomHygieneArray.length; i++){
                                    //获取所有复选框对象的value属性，然后，symptomArray[i]和他们匹配，如果有，则说明他应被选中
                                    $.each(roomHygieneAll,function(j,checkbox){
                                        //获取复选框的value属性
                                        var checkValue = $(checkbox).val();
                                        if(roomHygieneArray[i] == checkValue){
                                            $(checkbox).attr("checked",true);
                                            // $(checkbox).next().addClass('layui-form-checked');
                                        }
                                    });
                                }
                            } else if (key == 'medicalRecords') {
                                var medicalRecords = record.medicalRecords;
                                var medicalRecordsAll = $("input[name='medicalRecords']");
                                //获取所有复选框对象的value属性，然后，symptomArray[i]和他们匹配，如果有，则说明他应被选中
                                $.each(medicalRecordsAll,function(j,checkbox){
                                    //获取复选框的value属性
                                    var checkValue = $(checkbox).val();
                                    if(medicalRecords == checkValue){
                                        $(checkbox).attr("checked",true);
                                        // $(checkbox).next().addClass('layui-form-checked');
                                    }
                                });
                            } else {
                                $("[name='" + key + "']").val(record[key]);
                            }
                            $("[name='leaveDate']").val(record.leaveDateStr);

						}
                        layui.form.render();
					}
				});
			</#if>
            $(".ajax-form").unbind().submit(function () {
                try {
                    var form = $(this);
                    if (!form.valid()) {
                        $.message("验证不通过，无法提交表单");
                        return false;
                    }

                    form.formSubmit({
                        callBack:function (data) {
                            <#if (params.tag)??>
                            history.go(-1);
                            </#if>
                        }
                    });
                } catch (e) {
                    console.log("表单提交错误：" + e);
                }
                return false;
            });
		});
	</script>
</head>
<body>
	<div class="ui-form">
		<form class="layui-form ajax-form" action="${params.contextPath}/web/dischargeElderPreparation/<#if (params.id)??>modify<#else>save</#if>.json" method="post">
			<input type="hidden" name="id" value="${params.id}" />
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-row">
                        <div class="layui-col-md6">
                            <#if (params.tag)??>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">老人<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="hidden" name="elderId" id="elderId" value=""/>
                                        <input type="text" id="elderName" name="elderName" class="layui-input" autocomplete="off"/>
                                    </div>
                                </div>
                            <#else>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">老人<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="hidden" name="elderId"/>
                                        <input type="text" name="elderName" placeholder="请选择老人" p="model:'elder',handlerId:'elder_handler_select'" class="layui-input single-model-select {required:true}" readonly>
                                    </div>
                                </div>
                            </#if>
                        </div>
                        <div class="layui-col-md6">
                            <div class="layui-form-item">
                                <label class="layui-form-label">离院日期<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="leaveDate" placeholder="请输入离院日期" class="layui-input ui-date {required:true}" readonly/>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-row">
                        <div class="layui-col-md12">
                            <div class="layui-form-item">
                                <label class="layui-form-label">填写表格<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="fillForm" value="出院手续流转表" title="出院手续流转表">
                                    <input type="checkbox" name="fillForm" value="长者耗材单交于财务" title="长者耗材单交于财务">
                                    <input type="checkbox" name="fillForm" value="离院满意度调查表" title="离院满意度调查表">
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-row">
                        <div class="layui-col-md8">
                            <div class="layui-form-item">
                                <label class="layui-form-label">记录本<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="notebook" value="钥匙归还签字" title="钥匙归还签字">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md8">
                            <div class="layui-form-item">
                                <label class="layui-form-label">电表度数<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="powerMeter" placeholder="请输入电表度数" class="layui-input"/>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-row">
                        <div class="layui-col-md12">
                            <div class="layui-form-item">
                                <label class="layui-form-label">物品回收<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="itemRecycle" value="空调遥控器" title="空调遥控器">
                                    <input type="checkbox" name="itemRecycle" value="电视遥控器" title="电视遥控器">
                                    <input type="checkbox" name="itemRecycle" value="灭蚊器" title="灭蚊器">
                                    <input type="checkbox" name="itemRecycle" value="护理员服务记录表" title="护理员服务记录表">
                                    <input type="checkbox" name="itemRecycle" value="钥匙(房间、柜门)" title="钥匙(房间、柜门)">
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-row">
                        <div class="layui-col-md12">
                            <div class="layui-form-item">
                                <label class="layui-form-label">归还长者<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="returnElder" value="长者自带药" title="长者自带药">
                                    <input type="checkbox" name="returnElder" value="长者出院记录或体检表原件" title="长者出院记录或体检表原件">
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-row">
                        <div class="layui-col-md12">
                            <div class="layui-form-item">
                                <label class="layui-form-label">房间卫生<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="roomHygiene" value="监督护理员打扫卫生并检查" title="监督护理员打扫卫生并检查">
                                    <input type="checkbox" name="roomHygiene" value="房间布置整齐" title="房间布置整齐">
                                    <input type="checkbox" name="roomHygiene" value="紫外线消毒" title="紫外线消毒">
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-row">
                        <div class="layui-col-md12">
                            <div class="layui-form-item">
                                <label class="layui-form-label">病例整理<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="medicalRecords" value="按出院排列顺序,放入文件袋,存档" title="按出院排列顺序,放入文件袋,存档">
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-row">
                        <div class="layui-col-md12">
                            <div class="layui-form-item">
                                <label class="layui-form-label">其他特殊情况</label>
                                <div class="layui-input-block">
                                    <textarea name="otherSpecialCircumstances" placeholder="请输入其他特殊情况" class="layui-textarea"></textarea>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<input type="submit" value="保存" class="layui-btn" />
				</div>
			</div>
		</form>
	</div>
</body>
<script src="${params.contextPath}/static/plug/layui/layui.all.js"></script>
</html>
